package com.example.database;

import android.content.ContentValues;
import android.database.Cursor;

/**
 * A class representation of a row in table "Saldejums".
 */
public class Saldejums {

	// SQL convention says Table name should be "singular", so not Persons
	public static final String TABLE_NAME_ICECREAM = "IceCream";
	// Naming the id column with an underscore is good to be consistent
	// with other Android things. This is ALWAYS needed
	public static final String COL_ID = "_id";
	// These fields can be anything you want.
	public static final String COL_ITEM_CAT_CODE = "cat_code";
	public static final String COL_PRODUCT_GROUP_CODE = "group_code";
	public static final String COL_ITEM_CODE = "item_code";

	public static final String COL_DESCRIPTION_LV = "description_lv";
	
	public static final String COL_DESCRIPTION_ENG = "description_eng";
	
	public static final String COL_TOP_ITEM = "top_item";

	// For database projection so order is consistent
	public static final String[] FIELDS = { COL_ID, COL_ITEM_CAT_CODE, COL_PRODUCT_GROUP_CODE, COL_ITEM_CODE, COL_DESCRIPTION_LV, COL_DESCRIPTION_ENG, COL_TOP_ITEM};
	
	/*
	 * The SQL code that creates a Table for storing Group in.
	 * Note that the last row does NOT end in a comma like the others.
	 * This is a common source of error.
	 */
	public static final String CREATE_TABLE_ICECREAM_GROUP = 
			"CREATE TABLE " + TABLE_NAME_ICECREAM + "(" 
			+ COL_ID + " INTEGER PRIMARY KEY,"
			+ COL_ITEM_CAT_CODE + " INT,"
			+ COL_PRODUCT_GROUP_CODE + " INT,"
			+ COL_ITEM_CODE + " TEXT,"
			+ COL_DESCRIPTION_LV + " TEXT,"
			+ COL_DESCRIPTION_ENG + " TEXT,"
			+ COL_TOP_ITEM + " TEXT"
			+ ")";
	
	// Fields corresponding to database columns
	public long id = -1;
	public String cat_code = "";
	public String group_code = "";
	public String item_code = "";
	public String description_lv = "";
	public String description_eng = "";
	public String top_item = "";
	
	
	/**
	 * No need to do anything, fields are already set to default values above
	 */
	public Saldejums() {
	}

	/**
	 * Convert information from the database into a Person object.
	 */
	public Saldejums(final Cursor cursor) {
		// Indices expected to match order in FIELDS!
		this.id = cursor.getLong(0);
		this.cat_code = cursor.getString(1);
		this.group_code = cursor.getString(2);
		this.item_code = cursor.getString(3);
		this.description_lv = cursor.getString(4);
		this.description_eng = cursor.getString(5);
		this.top_item = cursor.getString(6);
	
	}

	/**
	 * Return the fields in a ContentValues object, suitable for insertion
	 * into the database.
	 */
	public ContentValues getContent() {
		final ContentValues values = new ContentValues();
		// Note that ID is NOT included here
		values.put(COL_ITEM_CAT_CODE, cat_code);
		values.put(COL_PRODUCT_GROUP_CODE, group_code);
		values.put(COL_ITEM_CODE, item_code);
		values.put(COL_DESCRIPTION_LV, description_lv);
		values.put(COL_DESCRIPTION_ENG, description_eng);
		values.put(COL_TOP_ITEM, top_item);
		
		

		return values;
	}
}
